/* Copyright (c) 2004-2024 Peigen.info. All rights reserved. */

package info.peigen.hotpot.business.customer.facade.order.register;

import cn.hutool.core.lang.Validator;
import cn.hutool.core.util.StrUtil;
import info.peigen.hotpot.business.customer.facade.order.base.CustomerServiceOrderBase;
import info.peigen.hotpot.common.core.result.ResultCode;
import info.peigen.hotpot.common.service.base.exception.BusinessException;
import lombok.*;
import lombok.experimental.Accessors;
import lombok.experimental.FieldDefaults;
import lombok.experimental.SuperBuilder;

/**
 * <b>(CustomerPreRegisterOrder)</b>
 *
 * @author Peigen
 * @version 1.0.0
 * @since 2021/7/28
 */
@EqualsAndHashCode(callSuper = true)
@SuperBuilder
@Data
@NoArgsConstructor
@AllArgsConstructor
@FieldDefaults(level = AccessLevel.PRIVATE)
@Accessors(chain = true)
public class CustomerPreRegisterOrder extends CustomerServiceOrderBase {
    /** 手机号 */
    String mobile;
    /** 邮件 */
    String email;

    @Override
    public void check() {
        super.check();
        if (StrUtil.isAllBlank(mobile, email)) {
            throw new BusinessException(ResultCode.PARAMETER_ERROR.code(), "mobile,email不可同时为空!");
        }

        if (StrUtil.isNotBlank(mobile)) {
            Validator.isMobile(mobile);
        }

        if (StrUtil.isNotBlank(email)) {
            Validator.isEmail(email);
        }
    }
}
